
<?php
 
/*
 * Following code will get single product details
 * A product is identified by product id (pid)
 */
 
// array for JSON response
$response = array();

// definiton


define('TABLE', "JOKE"); // db user
 
// include db connect class
require_once ('connect.php');
require_once ('build_object.php');
 
// connecting to db
$db = new CONNECT();
 

$str_query = getQueryString();

	$debug = 	$_GET['DEBUG'];
	if($debug==1){
		echo "<br> [query:] $str_query <br>";
	}
	  
$result = mysql_query("$str_query");

 
// check if row inserted or not
if ($result) {
    // successfully inserted into database
	$response["ID"] = mysql_insert_id();
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";

    // echoing JSON response
    echo json_encode($response);
} else {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";

    // echoing JSON response
    echo json_encode($response);
    
} 

//===========================================
function getQueryString(){

	$table = 	$_GET['TABLE'];
    $column = 	$_GET['COLUMN'];
	$value = 	$_GET['VALUE'];

	
	 $str_query 		= "INSERT INTO $table(";
	 $arr_column_names	= getColumnNames($table);
	 $cntColumns		= count($arr_column_names);

	
	 foreach($arr_column_names as $name){

		$str_query .= "$name,";
		
		
	 }
	 //delete komma
	 $str_query = substr_replace($str_query ,"",-1);
	 
	
	 
	 $str_query    .= ") VALUES(";
	
	 foreach($arr_column_names as $name){

		$value = $_GET["$name"];
		
		$str_query .= "'$value',";
		
	}
	 $str_query = substr_replace($str_query ,"",-1);
	 
	 $str_query		.= ")"; 	
	
	return $str_query;


}





?>